<!--工序报验---工序报验单---查看-->
<template>
  <div class="department" id="department">
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left">
          <el-radio-group
            v-model="radio"
            size="small"
            @change="modelType($event)"
          >
            <el-radio-button label="待办"></el-radio-button>
            <el-radio-button label="已办"></el-radio-button>
            <!-- #2b5a9d -->
          </el-radio-group>
        </div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="small"
              @click="yj_searchForm(getList)"
            ></el-button>

            <!-- <el-button
              type="primary"
              icon="el-icon-search"
              size="small"
              v-if="yj_view"
              @click="editText(fId)"
              >查看
            </el-button> -->

            <el-button
              type="primary"
              icon="el-icon-circle-plus-outline"
              size="small"
              v-if="getList.modelType == '0'"
              @click="edit(0)"
              >新增</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0'"
              @click="edit(1)"
              >编辑</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-circle-check"
              size="small"
              v-if="getList.modelType == '0'"
              @click="SubmitText(fId)"
              >提交</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0'"
              @click="edit(2)"
              >审核</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0'"
              @click="edit(3)"
              >审批</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="small"
              v-if="getList.modelType == '0'"
              @click="edit(4)"
              >签收</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-delete"
              size="small"
              v-if="getList.modelType == '0'"
              @click="rowDelete(fId)"
              >删除</el-button
            >
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @ClickOnLine="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />
        <pagination
          v-if="navigatepageNums > 1"
          :info="queryCriteriaData"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>

      <!--工序报验单 查看 -->
      <div class="Control-1 mechanism_dialogS closure">
        <el-dialog
          :title="dialogTitle"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden"
          >
            <div style="overflow-y: auto; margin-bottom: 20px">
              <div class="baseTitle">检验申请</div>
              <div class="publicForm" style="height: 220px">
                <publicForm
                  ref="publicForm"
                  lableWidth="125px"
                  :formObj="formObjText"
                  :formData="formData"
                  :timestamp="formData.fHandlefile"
                  :fileList="fHandlefileList"
                  @delteFile="delteFile"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>
              <div class="baseTitle" v-if="firstNum">监理员意见</div>
              <div class="publicForm" style="height: 130px" v-if="firstNum">
                <publicForm
                  ref="publicForm1"
                  lableWidth="125px"
                  :formObj="formObjText1"
                  :formData="formData"
                  :timestamp="formData.fQualityfile"
                  :fileList="fQualityfileList"
                  @delteFile="delteQualityFile"
                  @inputFocus="inputFocus"
                >
                </publicForm>
              </div>
              <div class="baseTitle" v-if="secondNum">监理工程师审批</div>
              <div class="publicForm" style="height: 80px" v-if="secondNum">
                <publicForm
                  ref="publicForm2"
                  lableWidth="125px"
                  :formObj="formObjText2"
                  :formData="formData"
                >
                </publicForm>
              </div>
              <div class="baseTitle" v-if="threeLevel">施工单位签收</div>
              <div class="publicForm" style="height: 80px" v-if="threeLevel">
                <publicForm
                  ref="publicForm3"
                  lableWidth="125px"
                  :formObj="formObjText3"
                  :formData="formData"
                >
                </publicForm>
              </div>
            </div>
          </div>
          <div class="newlyAdded_btn" v-if="btnShow">
            <el-button type="primary" @click="yj_saveForm()">保存</el-button>
            <el-button type="warning" @click="dialogEditVisible = false"
              >关闭</el-button
            >
          </div>
        </el-dialog>
      </div>

      <!-- 工程划分弹框 -->
      <div class="Control-1 mechanism_dialog ghgh">
        <el-dialog
          :close-on-click-modal="false"
          title="标段工程划分"
          v-dialogDrag
          :visible.sync="dialogTableVisibleDivide"
          v-loading="loadingDialogDivide"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div
            class="dialogBody common"
            :style="{ height: '650px' }"
            style="overflow: hidden; white: 100%"
          >
            <!-- 工程划分列表 -->
            <div class="text_table">
              <el-table
                ref="multipleTable"
                :data="tableData5"
                style="width: 100%"
                :height="navigatepageNums > 1 ? 'calc(100% - 20px)' : '100%'"
                border
                default-expand-all
                :tree-props="{
                  children: 'children',
                  hasChildren: 'hasChildren',
                }"
                row-key="F_CompanyId"
                v-loading="loadings"
                element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.2)"
                @row-click="getRowInfos"
                highlight-current-row
                @current-change="rowChange"
                stripe
              >
                <el-table-column
                  type="index"
                  label="序号"
                  width="50"
                  align="center"
                ></el-table-column>
                <el-table-column
                  prop="F_CompanyId"
                  label="工程编号"
                ></el-table-column>
                <el-table-column
                  prop="F_ShortName"
                  label="工程名称"
                ></el-table-column>
                <el-table-column prop="F_Nature" label="工程类别" width="90">
                </el-table-column>

                <template slot="empty">
                  <img
                    style="width: 285px; height: 208px"
                    src="@/assets/img/undata.png"
                    alt=""
                  />
                  <div class="pageFlagText">暂时没有数据哦！</div>
                </template>
              </el-table>
            </div>
            <div style="height: 40px">
              <div style="position: absolute; right: 5px; bottom: 0">
                <el-button type="primary" @click="engineeringSave(rowD)"
                  >保存</el-button
                >
                <el-button
                  type="warning"
                  @click="dialogTableVisibleDivide == false"
                  >关闭</el-button
                >
              </div>
            </div>
          </div>
        </el-dialog>
      </div>
      <!-- 工程划分弹框 -->
    </div>
  </div>
</template>

<script>
import {
  getWorkProcessDescriptionByFid, //详情
  saveWorkProcessDescription, //保存
  examineWorkProcessDescription, //监理员意见审核
  approveWorkProcessDescription, //监理工程师审批
  signWorkProcessDescription, //施工单位签收
  getWorkProcessDescriptionLists, //列表
  deleteWorkProcessDescription, //删除
  commitWorkProcessDescription, //提交
  // getTotalAmountDetail, //弹框2列表详情接口
  // getStationmachineByfMachineid, //调骨料名接口
  getBaseDepartmentUser, //查人员
  getWorkProcessProjectList, //工程划分列表
} from "@/api/request.js";
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import publicForm from "@/components/public/el-form.vue"; //弹框form
import formJs from "./regexDetail.js"; //新增弹框配置项

export default {
  inject: ["reload"],
  name: "ProcessInspectionText",
  data() {
    return {
      name: "ProcessInspectionText",
      //保存状态  0新增 1编辑 2审核 3审批 4签收
      saveStatus: 0,
      // 分页
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {},
      // 分页
      // yj_view: null,
      yj_add: null,
      yj_edit: null,
      yj_delete: null,
      yj_submit: null,
      radio: "待办",
      // 列表
      getList: formJs.getList,
      fId: null, //当前行数据fId
      loading: false, //列表转载
      table_config: formJs.table_configText,
      tableData: [], //表格列表数据列表
      // 列表
      firstNum: false, //一级审核显示
      secondNum: false, //二级审核显示
      threeLevel: false, //三级审核显示
      // 弹框
      timeYMD: null, //当前日期
      timeYMDS: null, //当前日期时分秒
      timeStamp: null, //当前日期时分秒
      btnShow: true,
      disabled: false,
      dialogTitle: "",
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      formObjText: null,
      formObjText1: null,
      formObjText2: null,
      formObjText3: null,
      formObj: formJs.formObj, //检验申请
      formObjs: formJs.formObjs, //检验申请查看
      formObjFirst: formJs.formObjFirst, //信息编辑配置参数
      formObjFirsts: formJs.formObjFirsts, //信息查看配置参数
      formObjFirst2: formJs.formObjFirst2, //信息编辑配置参数
      formObjFirst2s: formJs.formObjFirst2s, //信息查看配置参数
      formObjFirst3: formJs.formObjFirst3, //信息编辑配置参数
      formObjFirst3s: formJs.formObjFirst3s, //信息查看配置参数
      formData: formJs.formData,
      recordfiles: [], //删除文件
      fHandlefileList: [],
      fQualityfileList: [],
      saveData: formJs.saveData,
      getUserInitialList: [], //人员列表初始值
      getJLUserInitialList: [], //监理单位人员列表初始值
      getConsignerUserInitialList: [], //监理单位人员列表初始值
      // 弹框

      // 按工程划分新增
      loadings: false,
      dialogTableVisibleDivide: false,
      loadingDialogDivide: false,
      rowD: null,
      tableData5: [],
      fProjectpartid: null,
      fDnd: null,
      fProjectpart: null,
      // 按工程划分新增
      row: null,
      userInfo: {}, //登录用户
    };
  },
  components: {
    TableData, //主页面列表
    Pagination, //分页
    publicForm, //表单
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
  

    this.getList = {
      modelType: "0", // 0代办 1已办 不传或传空 表示列表页查询
      page: 1, //页码
      pageSize: 20, //每页条数
      projectId: "", // 查询条件项目ID
      companyId: "", // 查询条件标段ID
      stationId: "", // 查询条件拌合站ID
      machineId: "", // 查询条件拌合机ID
      fCompanyid: "", // 左侧选中组织机构id
      userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
    };
    this.getHeight();
    this.getData();
    this.getDatas();
    this.yj_searchForm(this.getList);
    this.btnRole(this.name);
    this.getUser(this.userInfo.companyId);
    this.getJLUser(this.userInfo.jlCompanyId);
  },
  methods: {
    btnRole(name) {
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
        this.yj_add = btnStr.includes("yj_add");
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_delete = btnStr.includes("yj_delete");
        this.yj_submit = btnStr.includes("yj_submit");
      } else {
        // this.yj_view = true;
        this.yj_add = true;
        this.yj_edit = true;
        this.yj_delete = true;
        this.yj_submit = true;
      }
    },

    modelType(e) {
      this.fId = "";
      this.row = "";
      if (e == "待办") {
        this.getList.modelType = "0";
        this.getList.userId = this.userInfo.userId;
        this.getList.fCompanyid = "";
      } else {
        this.getList.modelType = "1";
        this.getList.userId = this.userInfo.userId;
        this.getList.fCompanyid = "";
      }
      this.yj_searchForm(this.getList);
    },

    // 获取列表数据
    yj_searchForm(id) {
      this.loading = true;
      getWorkProcessDescriptionLists(id)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.loading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo;
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("列表", res.msg);
            this.loading = false;
          }
        })
        .catch(() => {
          console.log("列表");
          this.loading = false;
        });
    },
    edit(num) {
      this.recordfiles = [];
      this.formObjText = this.formObj;
      this.formObjText1 = this.formObjFirst;
      this.formObjText2 = this.formObjFirst2;
      this.formObjText3 = this.formObjFirst3;
      this.disabled = false;
      this.saveStatus = num;
      if (num == 0) {
        this.dialogTitle = "新增";
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        this.btnShow = true;
        this.firstNum = false; //监理员意见显示
        this.secondNum = false; //监理工程师审批显示
        this.threeLevel = false; //施工单位签收显示
        this.fHandlefileList = [];
        // this.formObjText.map((item) => {
        //   //工程报验单
        //   item.disabled = false; //工程报验单禁用
        //   item.uploadSelect = true; //上传附件按钮是否显示
        //   item.rules = []; //必填项不必填
        // });
        this.formData = {
          fId: null, // 配合比fid
          fCompanyid: this.userInfo.companyId, // 所属标段id
          fCompanyname: this.userInfo.companyName, // 所属标段名称
          fCompanyfullname: this.userInfo.companyFullName, // 所属标段名称
          fProjectid: this.userInfo.projectId, // 所属项目id
          fProjectname: this.userInfo.projectName, // 所属项目名称
          fProjectfullname: this.userInfo.projectFullName, // 所属项目名称
          fInspectionnumber: null, // 工程报验单编号
          fInspectionusername: this.userInfo.realName, // 报验记录人
          fInsectionuserid: this.userInfo.userId, // 报验记录人id*
          fDivisioncontractor: null, // 报验工程划分
          fDivisionContractorid: null, // 报验工程划分id
          fInsprctionprojectname: null, // 工程名称
          fConstructiondates: this.timeYMD, // 施工时间
          fInspectionproject: null, // 工程项目
          fRemarks: null, // 桩号及部位
          fCheckdescription: null, // 检验内容
          fProvingdates: null, // 要求到现场检验时间
          fSubmitdates: this.timeYMDS, // 承包人递交日期、时间
          fHandlefile: "Handlefile" + this.timeStamp, // 自检资料及影像资料
          fInspectorsubrid: null, // 提交监理员
          fInspectorsubname: null, // 提交监理员id
          fQualityfile: "Qualityfile" + this.timeStamp, // 附件：质量证明资料
          recordfiles: null, // 信息相关文件列表
        };
        // console.log("新增", this.formData);
        this.loadingEditDialog = false;
        // this.getConcrete();
      } else {
        if (this.fId != "" && this.fId != null) {
          if (
            num == 1 &&
            (this.row.fstatus == "编辑中" || this.row.fstatus == "已打回")
          ) {
            this.dialogTitle = "编辑";
            // this.formObjText.map((item) => {
            //   //工程报验单
            //   item.disabled = false; //工程报验单禁用
            //   item.uploadSelect = true; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            this.firstNum = false; //监理员意见显示
            this.secondNum = false; //监理工程师审批显示
            this.threeLevel = false; //施工单位签收显示
            this.btnShow = true;
            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete(this.fId);
          } else if (num == 2 && this.row.fstatus == "审核中") {
            this.dialogTitle = "审核";
            this.btnShow = true;
            this.firstNum = true; //监理员意见显示
            this.secondNum = false; //监理工程师审批显示
            this.threeLevel = false; //施工单位签收显示
            // this.formObjText.map((item) => {
            //   //工程报验单
            //   item.disabled = true; //闭合单禁用
            //   item.uploadSelect = false; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            // this.formObjText1.map((item) => {
            //   //审核
            //   item.disabled = false; //工程报验单禁用
            //   item.uploadSelect = true; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            this.formObjText = this.formObjs;

            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete2(this.fId);
          } else if (num == 3 && this.row.fstatus == "审批中") {
            this.dialogTitle = "审批";
            this.btnShow = true;
            this.firstNum = true; //监理员意见显示
            this.secondNum = true; //监理工程师审批显示
            this.threeLevel = false; //施工单位签收显示
            // this.formObjText.map((item) => {
            //   //工程报验单
            //   item.disabled = true; //工程报验单禁用
            //   item.uploadSelect = false; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            // this.formObjText1.map((item) => {
            //   //审核
            //   item.disabled = true; //工程报验单禁用
            //   item.uploadSelect = false; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            // this.formObjText2.map((item) => {
            //   //审批
            //   item.disabled = false; //工程报验单禁用
            //   item.uploadSelect = true; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            this.formObjText = this.formObjs;
            this.formObjText1 = this.formObjFirsts;

            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete3(this.fId);
          } else if (num == 4 && this.row.fstatus == "签收中") {
            this.dialogTitle = "签收";
            this.btnShow = true;
            this.firstNum = true; //监理员意见显示
            this.secondNum = true; //监理工程师审批显示
            this.threeLevel = true; //施工单位签收显示
            // this.formObjText.map((item) => {
            //   //工程报验单
            //   item.disabled = true; //工程报验单禁用
            //   item.uploadSelect = false; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            // this.formObjText1.map((item) => {
            //   //审核
            //   item.disabled = true; //工程报验单禁用
            //   item.uploadSelect = false; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            // this.formObjText2.map((item) => {
            //   //审批
            //   item.disabled = true; //工程报验单禁用
            //   item.uploadSelect = false; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            // this.formObjText3.map((item) => {
            //   //签收
            //   item.disabled = false; //工程报验单禁用
            //   item.uploadSelect = true; //上传附件按钮是否显示
            //   item.rules = []; //必填项不必填
            // });
            this.formObjText = this.formObjs;
            this.formObjText1 = this.formObjFirsts;
            this.formObjText2 = this.formObjFirst2s;

            this.loadingEditDialog = true; //弹框loading
            this.dialogEditVisible = true;
            this.getConcrete4(this.fId);
          } else {
            return this.$message.error("暂无此权限");
          }
        } else {
          return this.$message.error("请先选择需要编辑的数据");
        }
      }
    },
    // 获取详情
    getConcrete(id) {
      getWorkProcessDescriptionByFid({ fId: id })
        .then((res) => {
          this.loadingEditDialog = false; //弹框loading
          this.formData = res.data.WorkprocessDescription;
          this.fHandlefileList = res.data.fHandlefileList;
          this.fQualityfileList = res.data.fQualityfileList;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 获取详情
    getConcrete2(id) {
      getWorkProcessDescriptionByFid({ fId: id })
        .then((res) => {
          this.loadingEditDialog = false; //弹框loading
          this.formData = res.data.WorkprocessDescription;
          this.formData.fInspectorid = this.userInfo.userId; // 监理员id
          this.formData.fInspectorname = this.userInfo.realName; // 监理员
          this.formData.fCheckdates = this.timeYMD; // 审核时间
          this.formData.fCheckresultstatus = 1; // 审核结果
          this.formData.fCheckresult = "检验通过。"; // 审核结果
          this.fHandlefileList = res.data.fHandlefileList;
          this.fQualityfileList = res.data.fQualityfileList;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 获取详情
    getConcrete3(id) {
      getWorkProcessDescriptionByFid({ fId: id })
        .then((res) => {
          this.getConsigner(res.data.WorkprocessDescription.fCompanyid);
          this.loadingEditDialog = false; //弹框loading
          this.formData = res.data.WorkprocessDescription;
          this.formData.fEngineerid = this.userInfo.userId; //监理工程师id
          this.formData.fEngineername = this.userInfo.realName; //监理工程师姓名
          this.formData.fApprovaldates = this.timeYMD; //审批时间
          this.formData.fApprovalresultstatus = 1; //审批结果状态
          this.formData.fApprovalresult = "检验通过。"; //审批结果
          this.fHandlefileList = res.data.fHandlefileList;
          this.fQualityfileList = res.data.fQualityfileList;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 获取详情
    getConcrete4(id) {
      getWorkProcessDescriptionByFid({ fId: id })
        .then((res) => {
          this.getConsigner(res.data.WorkprocessDescription.fCompanyid);
          this.loadingEditDialog = false; //弹框loading
          this.formData = res.data.WorkprocessDescription;
          this.formData.fConsignerid = this.userInfo.userId; //签收人id
          this.formData.fConsignername = this.userInfo.realName; //签收人姓名
          this.formData.fSigndates = this.timeYMD; //签收时间
          this.formData.fSignresultstatus = 1; //签收结果状态
          this.formData.fSignresult = "已签收。"; //签收结果
          this.fHandlefileList = res.data.fHandlefileList;
          this.fQualityfileList = res.data.fQualityfileList;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 保存
    yj_saveForm() {
      if (this.saveStatus == 0 || this.saveStatus == 1) {
        if (this.$refs.publicForm.submitForm()) {
          this.getJLUserInitialList.map((v) => {
            if (this.formData.fInspectorsubname == v.fRealname) {
              this.formData.fInspectorsubrid = v.fUserid;
            }
          });
          this.saveData = {
            fId: this.formData.fId,
            fCompanyid: this.userInfo.companyId, // 所属标段id
            fCompanyname: this.userInfo.companyName, // 所属标段名称
            fCompanyfullname: this.userInfo.companyFullName, // 所属标段名称
            fProjectid: this.userInfo.projectId, // 所属项目id
            fProjectname: this.userInfo.projectName, // 所属项目名称
            fProjectfullname: this.userInfo.projectFullName, // 所属项目名称
            fInspectionnumber: this.formData.fInspectionnumber, // 工程报验单编号

            fDivisioncontractor: this.formData.fDivisioncontractor, // 报验工程划分
            fDivisionContractorid: this.formData.fDivisionContractorid, // 报验工程划分id
            fInspectionusername: this.userInfo.realName, // 报验记录人
            fInsectionuserid: this.userInfo.userId, // 报验记录人id*
            userName: this.userInfo.realName, // 当前登录人
            userId: this.userInfo.userId, // 当前登录id*

            fInsprctionprojectname: this.formData.fInsprctionprojectname, // 工程名称
            fConstructiondates: this.formData.fConstructiondates, // 施工时间
            fInspectionproject: this.formData.fInspectionproject, // 工程项目
            fRemarks: this.formData.fRemarks, // 桩号及部位
            fCheckdescription: this.formData.fCheckdescription, // 检验内容
            fProvingdates: this.formData.fProvingdates, // 要求到现场检验时间
            fSubmitdates: this.formData.fSubmitdates, // 承包人递交日期、时间
            fHandlefile: this.formData.fHandlefile, // 自检资料及影像资料
            fInspectorsubrid: this.formData.fInspectorsubrid, // 提交监理员id
            fInspectorsubname: this.formData.fInspectorsubname, // 提交监理员
            fQualityfile: this.formData.fQualityfile, // 附件：质量证明资料
            recordfiles: this.recordfiles, // 删除文件id集合
          };

          saveWorkProcessDescription(this.saveData)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("新增成功");
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log(error);
            });
        }
      } else if (this.saveStatus == 2) {
        if (this.$refs.publicForm1.submitForm()) {
          this.getUserInitialList.map((v) => {
            if (this.formData.fEngineersubname == v.fRealname) {
              this.formData.fEngineersubid = v.fUserid;
            }
          });
          if (this.formData.fCheckresult == "检验通过。") {
            this.formData.fCheckresultstatus = 1;
          } else {
            this.formData.fCheckresultstatus = 0;
          }
          this.saveData = {
            fId: this.formData.fId,
            fCheckresultstatus: this.formData.fCheckresultstatus, // 审核结果
            fCheckresult: this.formData.fCheckresult, // 审核结果
            fCheckdates: this.formData.fCheckdates, // 审核时间
            fInspectoropinion: this.formData.fInspectoropinion, // 监理员意见
            fInspectorname: this.formData.fInspectorname, // 监理员
            fInspectorid: this.formData.fInspectorid, // 监理员id
            fEngineersubname: this.formData.fEngineersubname, // 提交监理工程师
            fEngineersubid: this.formData.fEngineersubid, // 提交监理工程师*id
            recordfiles: this.recordfiles, // 删除文件id集合
          };
          examineWorkProcessDescription(this.saveData)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("审核成功");
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log(error);
            });
        }
      } else if (this.saveStatus == 3) {
        if (this.$refs.publicForm2.submitForm()) {
          this.getConsignerUserInitialList.map((v) => {
            if (this.formData.fConsignersubname == v.fRealname) {
              this.formData.fConsignersubid = v.fUserid;
            }
          });
          if (this.formData.fApprovalresult == "检验通过。") {
            this.formData.fApprovalresultstatus = 1;
          } else {
            this.formData.fApprovalresultstatus = 0;
          }
          this.saveData = {
            fId: this.formData.fId,
            fApprovalresultstatus: this.formData.fApprovalresultstatus, // 审批结果状态
            fApprovalresult: this.formData.fApprovalresult, // 审批结果
            fApprovaldates: this.formData.fApprovaldates, // 审批时间
            fEngineeropinion: this.formData.fEngineeropinion, // 监理工程师意见
            fEngineername: this.formData.fEngineername, // 监理工程师姓名
            fEngineerid: this.formData.fEngineerid, // 监理工程师id
            fConsignersubname: this.formData.fConsignersubname, // 提交施工单位签收人
            fConsignersubid: this.formData.fConsignersubid, // 提交施工单位签收人id
          };
          approveWorkProcessDescription(this.saveData)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("审核成功");
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log(error);
            });
        }
      } else if (this.saveStatus == 4) {
        if (this.$refs.publicForm2.submitForm()) {
          if (this.formData.fSignresult == "已签收。") {
            this.formData.fSignresultstatus = 1;
          } else {
            this.formData.fSignresultstatus = 0;
          }
          this.saveData = {
            fId: this.formData.fId,
            fSignresultstatus: this.formData.fSignresultstatus, // 签收结果状态
            fSignresult: this.formData.fSignresult, // 签收结果
            fSigndates: this.formData.fSigndates, // 签收时间
            fConsignerid: this.formData.fConsignerid, // 签收人id
            fConsignername: this.formData.fConsignername, // 签收人姓名
          };
          signWorkProcessDescription(this.saveData)
            .then((res) => {
              if (res.errcode == 0) {
                this.yj_searchForm(this.getList);
                this.dialogEditVisible = false;
                this.$message.success("签收成功");
              } else {
                this.$message.error(res.msg);
                console.log("接口报错");
              }
            })
            .catch((error) => {
              console.log(error);
            });
        }
      } else {
        console.log("error");
      }
    },

    // 提交
    SubmitText(id) {
      if (id != "" && id != null) {
        if (this.row.fstatus == "编辑中" || this.row.fstatus == "已打回") {
          this.$confirm("是否继续提交?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              commitWorkProcessDescription({
                fId: id,
                userId: this.userInfo.userId,
                userName: this.userInfo.realName,
              })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("提交成功");
                  } else {
                    this.$message.error("提交失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("提交失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消提交");
            });
        } else {
          return this.$message.error("暂无此权限");
        }
      } else {
        return this.$message.error("请先选择需要提交的数据");
      }
    },

    // 删除
    rowDelete(id) {
      if (id != "" && id != null) {
        if (this.row.fstatus == "编辑中") {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;
              deleteWorkProcessDescription({ fId: id })
                .then((res) => {
                  if (res.errcode == 0) {
                    this.loading = false;
                    this.yj_searchForm(this.getList);
                    this.$message.success("删除成功");
                  } else {
                    this.$message.error("删除失败", res.msg);
                    this.loading = false;
                  }
                })
                .catch(() => {
                  console.log("删除失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消删除");
            });
        } else {
          return this.$message.error("暂无此权限");
        }
      } else {
        return this.$message.error("请先选择需要删除的数据");
      }
    },

    // 获取页面容器高度
    getHeight() {
      var h = document.documentElement.clientHeight; //获取页面可见高度
      this.dialogHeight = h * 0.36 + "px";
    },
    // 点击查看
    yj_viewForm(row) {
      this.fId = row.fId;
      this.editText(this.fId);
    },

    // 查看
    editText(id) {
      this.formObjText = this.formObjs;
      this.formObjText1 = this.formObjFirsts;
      this.formObjText2 = this.formObjFirst2s;
      this.formObjText3 = this.formObjFirst3s;
      this.dialogTitle = "查看";
      this.btnShow = false;
      this.firstNum = false; //监理员意见显示
      this.secondNum = false; //监理工程师审批显示
      this.threeLevel = false; //施工单位签收显示

      this.disabled = true;
      if (id != "" && id != null) {
        this.loadingEditDialog = true; //弹框loading
        this.dialogEditVisible = true;
        getWorkProcessDescriptionByFid({ fId: id })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.loadingEditDialog = false;
              this.formData = res.data.WorkprocessDescription;
              this.fHandlefileList = res.data.fHandlefileList;
              this.fQualityfileList = res.data.fQualityfileList;

              this.btnShow = true;
              if (this.formData.fStatus == "审核中") {
                this.firstNum = true; //监理员意见显示
              }
              if (this.formData.fStatus == "审批中") {
                this.firstNum = true; //监理员意见显示
                this.secondNum = true; //监理工程师审批显示
              }
              if (this.formData.fStatus == "签收中") {
                this.firstNum = true; //监理员意见显示
                this.secondNum = true; //监理工程师审批显示
                this.threeLevel = true; //施工单位签收显示
              }
              if (this.formData.fStatus == "已完成") {
                this.firstNum = true; //监理员意见显示
                this.secondNum = true; //监理工程师审批显示
                this.threeLevel = true; //监理员意见显示
              }
              this.formObjText.map((item) => {
                //工程报验单
                item.disabled = true; //工程报验单禁用
                item.uploadSelect = false; //上传附件按钮是否显示
                item.rules = []; //必填项不必填
              });

              this.formObjText1.map((item) => {
                //工程报验单
                item.disabled = true; //工程报验单禁用
                item.uploadSelect = false; //上传附件按钮是否显示
                item.rules = []; //必填项不必填
              });
              this.formObjText2.map((item) => {
                //工程报验单
                item.disabled = true; //工程报验单禁用
                item.uploadSelect = false; //上传附件按钮是否显示
                item.rules = []; //必填项不必填
              });
              // this.formObjText3.map((item) => {
              //   //工程报验单
              //   item.disabled = true; //工程报验单禁用
              //   item.uploadSelect = false; //上传附件按钮是否显示
              //   item.rules = []; //必填项不必填
              // });
            } else {
              this.$message.error("查看", res.msg);
              this.loadingEditDialog = false;
            }
          })
          .catch(() => {
            console.log("查看---详情接口报错");
            this.loadingEditDialog = false;
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },

    // 提交监理工程师
    getUser(id) {
      getBaseDepartmentUser({ fCompanyid: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.getUserInitialList = []; //人员列表初始值
            var getUser = {
              value: "",
              label: "",
            };
            var getUserList = []; //人员列表过滤后
            res.data.childList.map((v) => {
              if (v.personList != undefined) {
                this.getUserInitialList = v.personList;
                this.getUserInitialList.map((v) => {
                  getUser = {
                    value: v.fRealname,
                    label: v.fRealname,
                  };
                  getUserList.push(getUser);
                });
              }
            });
            // console.log(
            //   "处理后的人员下拉框",
            //   this.getUserInitialList,
            //   getUserList
            // );

            this.formObjFirst[5].options = getUserList;
          } else {
            this.$message.error(res.msg);
            console.log("部门管理-查询部门列表以及下属人员,接口报错");
          }
        })
        .catch((error) => {
          console.log("部门管理-查询部门列表以及下属人员", error);
        });
    },

    // 提交监理员*
    getJLUser(id) {
      getBaseDepartmentUser({ fCompanyid: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.getJLUserInitialList = []; //人员列表初始值
            var getUser = {
              value: "",
              label: "",
            };
            var getUserList = []; //人员列表过滤后

            res.data.childList.map((v) => {
              if (v.personList != undefined) {
                this.getJLUserInitialList = v.personList;
                this.getJLUserInitialList.map((v) => {
                  getUser = {
                    value: v.fRealname,
                    label: v.fRealname,
                  };
                  getUserList.push(getUser);
                });
              }
            });

            // console.log(
            //   "处理后的人员下拉框",
            //   this.getJLUserInitialList,
            //   getUserList
            // );
            this.formObj[11].options = getUserList;
          } else {
            this.$message.error(res.msg);
            console.log("部门管理-查询部门列表以及下属人员,接口报错");
          }
        })
        .catch((error) => {
          console.log("部门管理-查询部门列表以及下属人员", error);
        });
    },

    //施工单位签收人
    getConsigner(id) {
      getBaseDepartmentUser({ fCompanyid: id })
        .then((res) => {
          if (res.errcode == 0) {
            this.getConsignerUserInitialList = []; //人员列表初始值

            var getUser = {
              value: "",
              label: "",
            };
            var getUserList = []; //人员列表过滤后

            res.data.childList.map((v) => {
              if (v.personList != undefined) {
              this.getConsignerUserInitialList = v.personList;
              this.getConsignerUserInitialList.map((v) => {
                getUser = {
                  value: v.fRealname,
                  label: v.fRealname,
                };
                getUserList.push(getUser);
              });
              }
            });
            // console.log(
            //   "处理后的人员下拉框",
            //   this.getConsignerUserInitialList,
            //   getUserList
            // );
            this.formObjFirst2[3].options = getUserList;
          } else {
            this.$message.error(res.msg);
            console.log("部门管理-查询部门列表以及下属人员,接口报错");
          }
        })
        .catch((error) => {
          console.log("部门管理-查询部门列表以及下属人员", error);
        });
    },

    getData() {
      var time = new Date();
      const y = time.getFullYear();
      const m = (time.getMonth() + 1 + "").padStart(2, "0");
      const d = (time.getDate() + "").padStart(2, "0");
      this.timeYMD = `${y}-${m}-${d}`;
    },
    // 弹框2
    getDatas() {
      let dt = new Date();
      var y = dt.getFullYear();
      var mt = (dt.getMonth() + 1).toString().padStart(2, "0");
      var day = dt.getDate().toString().padStart(2, "0");
      var h = dt.getHours().toString().padStart(2, "0");
      var m = dt.getMinutes().toString().padStart(2, "0");
      var s = dt.getSeconds().toString().padStart(2, "0");
      this.timeYMDS = y + "-" + mt + "-" + day + " " + h + ":" + m + ":" + s;
      this.timeStamp = Date.parse(y + "-" + mt + "-" + day + " " + h + ":" + m);
    },
    // 点击当前
    rowChange(val) {
      this.row = val;
      this.fId = val.fId;
    },
    // 刪除
    delteFile(file) {
     
      for (let index = 0; index < this.fHandlefileList.length; index++) {
        if (file.uid == this.fHandlefileList[index].uid) {
          if (this.fHandlefileList[index].atta == undefined) {
            this.recordfiles.push({
              fId: this.fHandlefileList[index].fId,
            });
          } else {
            this.recordfiles.push({
              fId: this.fHandlefileList[index].atta.fId,
            });
          }
          this.fHandlefileList.splice(index, 1);
        }
      }
     
    },
    delteQualityFile(file) {
      for (let index = 0; index < this.fQualityfileList.length; index++) {
        if (file.uid == this.fQualityfileList[index].uid) {
          if (this.fQualityfileList[index].atta == undefined) {
            this.recordfiles.push({
              fId: this.fQualityfileList[index].fId,
            });
          } else {
            this.recordfiles.push({
              fId: this.fQualityfileList[index].atta.fId,
            });
          }
          this.fQualityfileList.splice(index, 1);
        }
      }
     
    },
    inputFocus(index, prop) {
    
      if (prop == "fDivisioncontractor") {
        this.getDataList();
        return index;
      }
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},

    //工程划分新增
    getRowInfos(e) {
     
      this.rowD = e;
    },
    getDataList() {
      this.dialogTableVisibleDivide = true;
      this.loadingDialogDivide = true;
      getWorkProcessProjectList({ companyId: this.userInfo.companyId })
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            setTimeout(() => {
              this.loadingDialogDivide = false;
              that.tableData5 = this.tranListToTreeData(
                res.data.workProcessProjectList
              );
            
              this.$nextTick(() => {
                var that = this;
                that.$refs.multipleTable.doLayout();
              });
            }, 200);
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    tranListToTreeData(data) {
      let result = [];
      if (!Array.isArray(data)) {
        return result;
      }
      // 清除已存在的children 重新赋值
      data.forEach((item) => {
        delete item.children;
      });

      let map = {};
      data.forEach((item) => {
        map[item.F_CompanyId] = item;
      });

      data.forEach((item) => {
        let parent = map[item.F_ParentId];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });

      return result;
    },
    engineeringSave(data) {
      this.formData.fDivisioncontractor = data.F_TreeName; // 报验工程划分
      this.formData.fDivisionContractorid = data.F_EnCode; // 报验工程划分id
      // debugger;
      
      // fDivisioncontractor: null, // 报验工程划分
      // fDivisionContractorid: null, // 报验工程划分id
      this.$message.success("工程划分保存成功");
      this.dialogTableVisibleDivide = false;
      // if (data.children == undefined) {
      //   this.rowD = data;//这是工程划分获得的数据  要什么打点取
      //   this.$message.success("工程划分保存成功");
      //   this.dialogTableVisibleDivide = false;
      // } else {
      //   this.rowD = null;
      //   this.$message.warning("该条数据不符合要求");
      // }
    },
    //工程划分新增
  },
};
</script>

<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}
</style>